<template>
  <div class="JJTableSearch">
    <!-- Search items -->
    <div class="SearchBox">
      <template v-for="f in Object.values(searchOptions)"
        ><div class="SearchItem">
          <div class="SearchLabel">{{ f.label }}:</div>
          <!-- Input item -->
          <el-input
            v-if="f.type === 'input'"
            v-model="f.value"
            :placeholder="f.placeholder"
            :style="{ width: f.width + 'px' }"
            :clearable="f.clearable"
          />

          <!-- Dropdown item -->
          <el-select
            v-if="f.type === 'dropdown' && f.options && f.options.length !== 0"
            v-model="f.value"
            :placeholder="f.placeholder"
            :style="{ width: f.width + 'px' }"
            :clearable="f.clearable"
          >
            <el-option v-for="item in f.options" :key="item.value" :label="item.label" :value="item.value"> </el-option>
          </el-select>

          <!-- Date item -->
          <el-date-picker
            v-if="f.type === 'date'"
            v-model="f.value"
            type="date"
            :placeholder="f.placeholder"
            :style="{ width: f.width + 'px' }"
            :clearable="f.clearable"
          >
          </el-date-picker>

          <!-- Cascader item -->
          <!-- TODO -->
        </div>
      </template>
    </div>

    <!-- Option items -->
    <div class="OptionBox">
      <el-row>
        <el-button type="primary">Search</el-button>
        <el-button>Reset</el-button>
        <!-- TODO expand button -->
        <!-- <el-button type="text">Expand</el-button> -->
      </el-row>
    </div>
  </div>
</template>

<script>
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'JJTableSearch',
  props: ['searchOptions']
})
</script>

<style lang="scss">
.JJTableSearch {
  display: flex;
  padding: var(--u-gap);
  background-color: var(--c-bg);

  .SearchBox {
    display: flex;
    flex-wrap: wrap;
    flex-grow: 1;
    column-gap: calc(var(--u-gap) * 2);
    row-gap: var(--u-gap);

    .SearchItem {
      display: flex;
      align-items: center;

      .SearchLabel {
        width: 50px;
        text-align: right;
        margin-right: var(--u-gap);
        font-size: 14px;
      }

      .el-input__inner {
        padding: 0 var(--u-gap);
        border-radius: 0;
        height: 26px;
        line-height: 26px;
      }

      .el-date-editor {
        .el-input__inner {
          padding-left: 30px;
        }
      }

      .el-input__icon {
        line-height: 26px;
      }
    }
  }

  .OptionBox {
    margin: auto 0;
    margin-left: calc(var(--u-gap) * 2);
    flex-shrink: 0;

    .el-button {
      padding: 0 12px;
      height: 26px;
      line-height: 26px;
      font-size: 14px;
      border-radius: 0;
      column-gap: 16px;

      &:last-child {
        margin-left: var(--u-gap);
      }
    }
  }
}
</style>
